package domain;

import java.util.HashSet;
import java.util.Set;

public class Segment {

	public Segment(float x, float y) {
		this.x = x;this.y = y;
		this.car = null;
	}
	
	/* coordinaten */
	public float getX() {return x;}
	public float getY() {return y;}
	
	private final float x,y;
	
	/*   Car   */
	public Car getCar(){
		return car;
	}
	
	//mag alleen door car veranderd worden
	void setCar(Car car){
		this.car = car;
		notifyObservers();
	}
	void removeCar(){
		car = null;
		notifyObservers();
	}
	
	private Car car;
	
	/* CarChangeObserver */
	
	public interface CarChangeObserver {
		public void notifyCarChange();
	}
	
	public void subscribeCarChangeObserver(CarChangeObserver obs) {
		observers.add(obs);
	}
	
	public void unsubscribeCarChangeObserver(CarChangeObserver obs) {
		observers.remove(obs);
	}
	
	private void notifyObservers() {
		for(CarChangeObserver obs : observers) {
			obs.notifyCarChange();
		}
	}
	
	private Set<CarChangeObserver> observers = new HashSet<CarChangeObserver>();
	
}
